package org.grayrabbit.cloud.core.telnet;

public class VT100PrintUtilities implements TelnetServiceConstants {
	public static final byte[] RESET = { 27, 91, 48 };

	public static final byte[] MORE = { 59 };

	public static final byte[] DONE = { 109 };

	public static final byte[] STYLE_BOLD = { 49 };
	public static final byte[] STYLE_DIM = { 50 };
	public static final byte[] STYLE_UNDERSCORE = { 52 };
	public static final byte[] STYLE_BLINK = { 53 };
	public static final byte[] STYLE_REVERSE = { 55 };
	public static final byte[] STYLE_HIDDEN = { 56 };

	public static final byte[] ATTRS_FORE_BLACK = { 51, 48, 59, 52, 55 };
	public static final byte[] ATTRS_FORE_RED = { 51, 49 };
	public static final byte[] ATTRS_FORE_GREEN = { 51, 50 };
	public static final byte[] ATTRS_FORE_YELLOW = { 51, 51 };
	public static final byte[] ATTRS_FORE_BLUE = { 51, 52 };
	public static final byte[] ATTRS_FORE_MAGENTA = { 51, 53 };
	public static final byte[] ATTRS_FORE_CYAN = { 51, 54 };
	public static final byte[] ATTRS_FORE_WHITE = { 51, 55 };

	public static final byte[] ATTRS_BACK_BLACK = { 52, 48 };
	public static final byte[] ATTRS_BACK_RED = { 52, 49 };
	public static final byte[] ATTRS_BACK_GREEN = { 52, 50 };
	public static final byte[] ATTRS_BACK_YELLOW = { 52, 51 };
	public static final byte[] ATTRS_BACK_BLUE = { 52, 52 };
	public static final byte[] ATTRS_BACK_MAGENTA = { 52, 53 };
	public static final byte[] ATTRS_BACK_CYAN = { 51, 48, 59, 52, 54 };
	public static final byte[] ATTRS_BACK_WHITE = { 51, 48, 59, 52, 55 };

	public static final byte[][] ATTRS_DEFAULT = { RESET, DONE };

	public static StringBuffer setAttrs(StringBuffer buffer, byte[][] attrs) {
		for (int i = 0; i < attrs.length; i++) {
			for (int j = 0; j < attrs[i].length; j++) {
				buffer.append((char) attrs[i][j]);
			}
		}
		return buffer;
	}

	public static StringBuffer resetAttrs(StringBuffer buffer) {
		return setAttrs(buffer, ATTRS_DEFAULT);
	}
}
